//
//  HYGameInfoDetailCell.m
//  HaiYue
//
//  Created by skyline on 2018/5/16.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYGameInfoDetailCell.h"
#import "HYGameInfoDetailScrollIMG.h"
#import "HYIMGScrollView.h"
#import "HYMoreBtn.h"
@interface HYGameInfoDetailCell()<HYGameInfoDetailScrollIMGDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) HYGameInfoDetailScrollIMG *scrollSmallIMG;//小的滚动图片
@property (nonatomic, strong) HYIMGScrollView *scrollBackIMG;//大的滚动图片
@property (nonatomic, strong) HYLabel *introLBL;//简介
@property (nonatomic, strong) HYLabel *contentLBL;//内容
@property (nonatomic, strong) HYLabel *gameTitleLBL;//游戏信息
@property (nonatomic, strong) HYLabel *sizeLBL;//大小
@property (nonatomic, strong) HYLabel *versionLBL;//版本
@property (nonatomic, strong) HYLabel *systemLBL;//系统
@property (nonatomic, strong) HYLabel *typeLBL;//类别
@property (nonatomic, strong) HYLabel *languageLBL;//语言
@property (nonatomic, strong) HYLabel *timeLBL;//时间
@property (nonatomic, strong) HYMoreBtn *moreBtn;//更多
@end
@implementation HYGameInfoDetailCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
//        self.contentLBL.text = @"《乱世王者》是由腾讯旗下天美工作室群自主研发的一款战争策略手游！作为历史架空题材的游戏，《乱世王者》最大限度还原了战争策略游戏的精髓，将烽火乱世从战争层面到战略层面进行精彩演绎，玩家将化身为在增额乱世中的一方诸侯，从经营封地到招兵买马，逐步走向稳定天下的争霸之路乱世王者》是由腾讯旗下天美工作室群自主研发的一款战争策略手游！作为历史架空题材的游戏，《乱世王者》最大限度还原了战争策略游戏的精髓，将烽火乱世从战争层面到战略层面进行精彩演绎，玩家将化身为在增额乱世中的一方诸侯，从经营封地到招兵买马，逐步走向稳定天下的争霸之路乱世王者》是由腾讯旗下天美工作室群自主研发的一款战争策略手游！作为历史架空题材的游戏，《乱世王者》最大限度还原了战争策略游戏的精髓，将烽火乱世从战争层面到战略层面进行精彩演绎，玩家将化身为在增额乱世中的一方诸侯，从经营封地到招兵买马，逐步走向稳定天下的争霸之路乱世王者》是由腾讯旗下天美工作室群自主研发的一款战争策略手游！作为历史架空题材的游戏，《乱世王者》最大限度还原了战争策略游戏的精髓，将烽火乱世从战争层面到战略层面进行精彩演绎，玩家将化身为在增额乱世中的一方诸侯，从经营封地到招兵买马，逐步走向稳定天下的争霸之路";
        self.contentLBL.numberOfLines = (self.contentLBL.bounds.size.height > self.contentLBL.HeightLine * 3)?3:0;
//        self.languageLBL.hidden = NO;
//        self.timeLBL.hidden = NO;
    }
    return self;
}

- (UIScrollView *)scrollView
{
    if (!_scrollView)
    {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.bounces = NO;
        _scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, GAP * 7);
        [self addSubview:_scrollView];
        [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsZero);
        }];
    }
    return _scrollView;
}

- (HYIMGScrollView *)scrollBackIMG
{
    if (!_scrollBackIMG)
    {
        _scrollBackIMG = [[HYIMGScrollView alloc] init];
        _scrollBackIMG.level = HYIMGScrollViewLevelStatus;
    }
    return _scrollBackIMG;
}

- (HYGameInfoDetailScrollIMG *)scrollSmallIMG
{
    if (!_scrollSmallIMG)
    {
        _scrollSmallIMG = [[HYGameInfoDetailScrollIMG alloc] init];
        _scrollSmallIMG.hydelegate = self;
        _scrollSmallIMG.bounces = NO;
        _scrollSmallIMG.bounds = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT / 3.0);
        _scrollView.contentSize = CGSizeMake(_scrollView.contentSize.width, _scrollView.contentSize.height + _scrollSmallIMG.bounds.size.height);
        [self.scrollView addSubview:_scrollSmallIMG];
        [_scrollSmallIMG mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.scrollView);
            make.left.equalTo(self.scrollView);
            make.width.mas_offset(self.scrollSmallIMG.bounds.size.width);
            make.height.mas_offset(self.scrollSmallIMG.bounds.size.height);
        }];
    }
    return _scrollSmallIMG;
}

- (HYLabel *)introLBL
{
    if (!_introLBL)
    {
        _introLBL = [[HYLabel alloc] initWithText:@"简介:" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:14 weight:UIFontWeightBold]];
        _scrollView.contentSize = CGSizeMake(_scrollView.contentSize.width, _scrollView.contentSize.height + _introLBL.bounds.size.height);
        [self.scrollView addSubview:_introLBL];
        [_introLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.scrollView).with.offset(self.scrollSmallIMG.bounds.size.height + GAP);
            make.left.equalTo(self).with.offset(GAP);
        }];
    }
    return _introLBL;
}

- (HYLabel *)contentLBL
{
    if (!_contentLBL)
    {
        
        _contentLBL = [[HYLabel alloc] initWithText:@"" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight]];
        _contentLBL.fixedWidth = SCREEN_WIDTH - 2 * GAP;
        [self.scrollView addSubview:_contentLBL];
        [_contentLBL mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.introLBL.mas_bottom).with.offset(GAP);
            make.left.equalTo(self).with.offset(GAP);
            make.right.equalTo(self).with.offset(-GAP);
        }];
        
    }
    return _contentLBL;
}

- (HYMoreBtn *)moreBtn
{
    if (!_moreBtn)
    {
        _moreBtn = [[HYMoreBtn alloc] init];
        [_moreBtn addTarget:self action:@selector(actionForMoreBtn:) forControlEvents:UIControlEventValueChanged];
        _scrollView.contentSize = CGSizeMake(_scrollView.contentSize.width, _scrollView.contentSize.height + 2 *GAP);
        [self addSubview:_moreBtn];
        [_moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentLBL.mas_bottom);
            make.left.equalTo(self).with.offset(GAP);
            make.right.equalTo(self).with.offset(-GAP);
            make.height.mas_offset(GAP * 2);
        }];
    }
    return _moreBtn;
}

- (HYLabel *)gameTitleLBL
{
    if (!_gameTitleLBL)
    {
        _gameTitleLBL = [[HYLabel alloc] initWithText:@"游戏信息:" textColor:TEXT_BLACK_COLOR textFont:[UIFont systemFontOfSize:14 weight:UIFontWeightBold]];
        _scrollView.contentSize = CGSizeMake(_scrollView.contentSize.width, _scrollView.contentSize.height + _gameTitleLBL.bounds.size.height);
        [self.scrollView addSubview:_gameTitleLBL];
        [_gameTitleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self.moreBtn.mas_bottom).with.offset(GAP);
        }];
    }
    return _gameTitleLBL;
}

- (HYLabel *)sizeLBL
{
    if (!_sizeLBL)
    {
        _sizeLBL = [[HYLabel alloc] initWithText:@"大小:" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight]];
        _scrollView.contentSize = CGSizeMake(_scrollView.contentSize.width, _scrollView.contentSize.height + _sizeLBL.bounds.size.height);
        [self.scrollView addSubview:_sizeLBL];
        [_sizeLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.gameTitleLBL.mas_bottom).with.offset(GAP);
            make.left.equalTo(self).with.offset(GAP);
        }];
    }
    return _sizeLBL;
}

- (HYLabel *)systemLBL
{
    if (!_systemLBL)
    {
        _systemLBL = [[HYLabel alloc] initWithText:@"系统:" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight]];
        _scrollView.contentSize = CGSizeMake(_scrollView.contentSize.width, _scrollView.contentSize.height + _systemLBL.bounds.size.height);
        [self.scrollView addSubview:_systemLBL];
        [_systemLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self.sizeLBL.mas_bottom).with.offset(GAP);
        }];
    }
    return _systemLBL;
}

- (HYLabel *)languageLBL
{
    if (!_languageLBL)
    {
        _languageLBL = [[HYLabel alloc] initWithText:@"语言:" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight]];
        _scrollView.contentSize = CGSizeMake(_scrollView.contentSize.width, _scrollView.contentSize.height + _languageLBL.bounds.size.height);
        [self.scrollView addSubview:_languageLBL];
        [_languageLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(GAP);
            make.top.equalTo(self.systemLBL.mas_bottom).with.offset(GAP);
        }];
    }
    return _languageLBL;
}

- (HYLabel *)versionLBL
{
    if (!_versionLBL)
    {
        _versionLBL = [[HYLabel alloc] initWithText:@"版本:" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight]];
        [self.scrollView addSubview:_versionLBL];
        [_versionLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_centerX).with.offset(GAP);
            make.top.equalTo(self.gameTitleLBL.mas_bottom).with.offset(GAP);
        }];
    }
    return _versionLBL;
}

- (HYLabel *)typeLBL
{
    if (!_typeLBL)
    {
        _typeLBL = [[HYLabel alloc] initWithText:@"类别:" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight]];
        [self.scrollView addSubview:_typeLBL];
        [_typeLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_centerX).with.offset(GAP);
            make.top.equalTo(self.versionLBL.mas_bottom).with.offset(GAP);
        }];
    }
    return _typeLBL;
}

- (HYLabel *)timeLBL
{
    if (!_timeLBL)
    {
        _timeLBL = [[HYLabel alloc] initWithText:@"时间:" textColor:TEXT_GRAY_COLOR textFont:[UIFont systemFontOfSize:TipsFont weight:UIFontWeightLight]];
        [self.scrollView addSubview:_timeLBL];
        [_timeLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_centerX).with.offset(GAP);
            make.top.equalTo(self.typeLBL.mas_bottom).with.offset(GAP);
        }];
    }
    return _timeLBL;
}

- (void)setModel:(HYGameDetailModel *)model
{
    if (_model != model)
    {
        _model = model;
        self.scrollSmallIMG.imageNames = _model.piclist;
        self.contentLBL.text = _model.desc;
        self.sizeLBL.text = [NSString stringWithFormat:@"大小: %@", _model.size];
        self.versionLBL.text = [NSString stringWithFormat:@"版本: %@", _model.vesion];
//        self.systemLBL.text = [NSString stringWithFormat:@"系统: iOS8.0以上", _model.platform];
        self.systemLBL.text = @"系统: iOS8.0以上";
        self.typeLBL.text = [NSString stringWithFormat:@"类别: %@", _model.type];
        self.languageLBL.text = [NSString stringWithFormat:@"语言: %@", _model.lang];
        self.timeLBL.text = [NSString stringWithFormat:@"时间: %@", _model.date];
        self.scrollView.contentSize = CGSizeMake(self.scrollView.contentSize.width, self.scrollView.contentSize.height + self.contentLBL.bounds.size.height);
    }
}

- (void)actionForMoreBtn:(HYMoreBtn *)sender
{
    sender.selected = !sender.selected;
    self.scrollView.contentSize = CGSizeMake(self.scrollView.contentSize.width, self.scrollView.contentSize.height - self.contentLBL.bounds.size.height);
    self.contentLBL.numberOfLines = (sender.selected)?0:3;
    self.scrollView.contentSize = CGSizeMake(self.scrollView.contentSize.width, self.scrollView.contentSize.height + self.contentLBL.bounds.size.height);
    
}

#pragma mark - HYGameInfoDetailScrollIMGDelegate
- (void)scrollItemSelectedIndex:(NSInteger)index
{
    self.scrollBackIMG.hidden = NO;
    self.scrollBackIMG.items = self.scrollSmallIMG.itmes;
    self.scrollBackIMG.currentIndex = index;
}
@end
